package com.liu.yubi.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lqh
 * @since 2025-06-14 15:05
 * 跨域
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //允许发送cookie
                .allowCredentials (true)
                //放行那些域名（必须用 patterns，否则 * 会和 allowCredentials 冲突）
                .allowedOriginPatterns ("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders ("*")
                .exposedHeaders ("*");
    }
}
